package drds.data_migrate.task_group.task.data_exchange.exchanger;

import com.alibaba.fastjson.JSON;
import drds.common.Author;
import drds.data_migrate.Authors;
import drds.data_migrate.task_group.task.data_exchange.record.Record;
import drds.data_migrate.task_group.task.data_exchange.record.column.Column;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Author(name = Authors.LI_YANG)
public class DirtyRecord implements Record
{
    @Setter
    @Getter
    private List<Column> columnList = new ArrayList<Column>();

    public static DirtyRecord asDirtyRecord(final Record record)
    {
        DirtyRecord dirtyRecord = new DirtyRecord();
        for (int i = 0; i < record.getColumnListSize(); i++)
        {
            dirtyRecord.addColumn(record.getColumn(i));
        }

        return dirtyRecord;
    }

    //只能依次追加
    public void addColumn(Column column)
    {
        this.columnList.add(
                DirtyColumn.asDirtyColumn(column, this.columnList.size()));
    }


    public void setColumn(int index, Column column)
    {
        throw new RuntimeException("该方法不支持!");
    }

    public int getColumnListSize()
    {
        throw new RuntimeException("该方法不支持!");
    }

    public Column getColumn(int index)
    {
        throw new RuntimeException("该方法不支持!");
    }


    public int getByteSize()
    {
        throw new RuntimeException("该方法不支持!");
    }


    public int getMemoryByteSize()
    {
        throw new RuntimeException("该方法不支持!");
    }

    @Override
    public String toString()
    {
        return JSON.toJSONString(this.columnList);
    }


}

